
type lifeCycle = () => void;

// const scenesStartList: Array<lifeCycle> = [];
// const scenesUpdateList: Array<lifeCycle> = [];
const stageMap = new Map() 
const scenesMap = new Map() 
const spriteMap = new Map()  // { [id]:{ start: Array<lifeCycle>  , update :Array<lifeCycle>} }

class BaseManager {
    public static Instance: BaseManager;
    constructor() {

    }
    Start() {
        console.log('spriteMap Start', spriteMap);
        spriteMap.forEach(item => {
            item['start'].forEach(start => {
                start()
            })
        })
        stageMap.forEach(item => {
            item['start'].forEach(start => {
                start()
            })
        })
    }

    Update() {
      
        spriteMap.forEach(item => {
       
            item['update'].forEach(update => {
               
                update()
            })
        })
        stageMap.forEach(item => {
            item['update'].forEach(update => {
                update()
            })
        })
    }

    addSpriteLifeCycle(uid: number, lifeCycle: any) {
       
        spriteMap.set(uid, lifeCycle)
        console.log('spriteMap', spriteMap);
    }
    addScenesLifeCycle(uid: number, lifeCycle: any) {
        scenesMap.set(uid, lifeCycle)
    }

    addStageLifeCycle(uid: number, lifeCycle: any) {
        stageMap.set(uid, lifeCycle)
    }


    public static getInstance() {
        if (!BaseManager.Instance) {
            BaseManager.Instance = new BaseManager();
        }
        return BaseManager.Instance;
    }
}


export default BaseManager.getInstance();
